package com.ruoyi.source.service.impl;

import java.util.Arrays;
import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.source.api.domain.SrcCropGrow;
import com.ruoyi.source.mapper.SrcCropGrowMapper;
import com.ruoyi.source.service.ISrcCropGrowService;
import org.springframework.stereotype.Service;


/**
 * 农作物生长情况Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@Service
public class SrcCropGrowServiceImpl extends ServiceImpl<SrcCropGrowMapper,SrcCropGrow> implements ISrcCropGrowService {

    /**
     * 查询农作物生长情况
     * 
     * @param growId 农作物生长情况主键
     * @return 农作物生长情况
     */
    @Override
    public SrcCropGrow selectSrcCropGrowByGrowId(Long growId) {
        return baseMapper.selectById(growId);
    }

    /**
     * 查询农作物生长情况列表
     * 
     * @param srcCropGrow 农作物生长情况
     * @return 农作物生长情况
     */
    @Override
    public IPage<SrcCropGrow> selectSrcCropGrowList(IPage<SrcCropGrow> ipage,SrcCropGrow srcCropGrow) {
        LambdaQueryWrapper<SrcCropGrow> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SrcCropGrow::getCropId,srcCropGrow.getCropId())
                .between(ObjectUtils.isNotEmpty(srcCropGrow.getParams().get("beginTime")) && ObjectUtils.isNotEmpty(srcCropGrow.getParams().get("endTime")),SrcCropGrow::getCreateTime,srcCropGrow.getParams().get("beginTime"),srcCropGrow.getParams().get("endTime"));
        return baseMapper.selectPage(ipage,wrapper);
    }

    /**
     * 新增农作物生长情况
     * 
     * @param srcCropGrow 农作物生长情况
     * @return 结果
     */
    @Override
    public int insertSrcCropGrow(SrcCropGrow srcCropGrow) {
        srcCropGrow.setCreateBy(SecurityUtils.getUsername());
        srcCropGrow.setCreateTime(new Date());
        return baseMapper.insert(srcCropGrow);
    }

    /**
     * 修改农作物生长情况
     * 
     * @param srcCropGrow 农作物生长情况
     * @return 结果
     */
    @Override
    public int updateSrcCropGrow(SrcCropGrow srcCropGrow) {
        srcCropGrow.setUpdateBy(SecurityUtils.getUsername());
        srcCropGrow.setUpdateTime(new Date());
        return baseMapper.updateById(srcCropGrow);
    }

    /**
     * 批量删除农作物生长情况
     * 
     * @param growIds 需要删除的农作物生长情况主键
     * @return 结果
     */
    @Override
    public int deleteSrcCropGrowByGrowIds(Long[] growIds) {
        return baseMapper.deleteBatchIds(Arrays.asList(growIds));
    }

    /**
     * 删除农作物生长情况信息
     * 
     * @param growId 农作物生长情况主键
     * @return 结果
     */
    @Override
    public int deleteSrcCropGrowByGrowId(Long growId) {
        return baseMapper.deleteById(growId);
    }
}
